local fengkuangpaidui = fk.CreateSkill{
    name = "ym2__fengkuangpaidui",
    tags = {"Phase"},
}
local DIY = require "packages/diy_utility/diy_utility"
Fk:loadTranslationTable{
    ["ym2__fengkuangpaidui"] = "疯狂派对",
    [":ym2__fengkuangpaidui"] = "阶段技，你可以将一张牌当【火攻】使用并与目标各重铸一张牌，结算后你与其依次获得中央区一或两张牌，获得两张的一方失去1点体力，且本轮对另一方使用牌无距离和次数限制。",
    ["#ym2__fengkuangpaidui-ask"] = "疯狂派对：重铸一张牌",
    ["#ym2__fengkuangpaidui-card"] = "疯狂派对：获得中央区内一或两张牌",
    ["@[player]ym2__fengkuangpaidui-round"] = "疯狂派对",
}
fengkuangpaidui:addEffect("viewas",{
    pattern = "fire_attack",
    card_filter = Util.TrueFunc,
    card_num = 1,
    max_phase_use_time = 1,
    view_as = function (self, player, cards)
        if #cards ~= 1 then return end
        local card = Fk:cloneCard("fire_attack")
        card.skillName = fengkuangpaidui.name
        card:addSubcards(cards)
        return card
    end,
    after_use = function (self, player, use)
        local room = player.room
        local loser = {}
        local tos = use.tos
        local cards = room:askToChooseCards(player, {
            max = 2,
            min = 1,
            target = player,
            flag = { card_data = {{ "@$CenterArea", room:getBanner("@$CenterArea") }} },
            skill_name = fengkuangpaidui.name,
            prompt = "#ym2__fengkuangpaidui-card",
        })
        if #cards == 2 then
            table.insertIfNeed(loser,player)
        end
        room:obtainCard(player,cards,true,fk.ReasonJustMove,player,fengkuangpaidui.name)
        for _, to in ipairs(tos) do
            if to:isAlive() then
                cards = room:askToChooseCards(to, {
                    max = 2,
                    min = 1,
                    target = to,
                    flag = { card_data = {{ "@$CenterArea", room:getBanner("@$CenterArea") }} },
                    skill_name = fengkuangpaidui.name,
                    prompt = "#ym2__fengkuangpaidui-card",
                })
                if #cards == 2 then
                    table.insertIfNeed(loser,to)
                end
                room:obtainCard(to,cards,true,fk.ReasonJustMove,to,fengkuangpaidui.name)
            end
        end
        if table.contains(loser,player) then
            local mark = player:getTableMark("@[player]ym2__fengkuangpaidui-round")
            for _, to in ipairs(tos) do
                if to:isAlive() then
                    table.insertIfNeed(mark,to.id)
                end
            end
            room:setPlayerMark(player,"@[player]ym2__fengkuangpaidui-round",mark)
        end
        for _, tp in ipairs(loser) do
            if table.contains(use.tos,tp) then
                local mark = tp:getTableMark("@[player]ym2__fengkuangpaidui-round")
                table.insertIfNeed(mark,player.id)
                room:setPlayerMark(tp,"@[player]ym2__fengkuangpaidui-round",mark)
            end
            room:loseHp(tp,1,fengkuangpaidui.name)
        end
    end,
    enabled_at_play = function (self, player)
        return player:usedSkillTimes(fengkuangpaidui.name,player.HistoryPhase) < 1
    end,
    enabled_at_response = Util.FalseFunc,
})
fengkuangpaidui:addEffect(fk.CardUsing,{
    can_refresh = function (self, event, target, player, data)
        return target == player and data.card.skillName == fengkuangpaidui.name
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        if not player:isNude() then
            local card = room:askToCards(player, {
                min_num = 1,
                max_num = 1,
                include_equip = true,
                skill_name = fengkuangpaidui.name,
                prompt = "#ym2__fengkuangpaidui-ask",
                cancelable = false,
            })
            room:recastCard(card, player, fengkuangpaidui.name)
        end
        for _, to in ipairs(data.tos) do
            if to:isAlive() and not to:isNude() then
                local card = room:askToCards(to, {
                    min_num = 1,
                    max_num = 1,
                    include_equip = true,
                    skill_name = fengkuangpaidui.name,
                    prompt = "#ym2__fengkuangpaidui-ask",
                    cancelable = false,
                })
                room:recastCard(card, to, fengkuangpaidui.name)
            end
        end
    end,
})
fengkuangpaidui:addEffect("targetmod",{
    global = true,
    bypass_times = function(self, player, skill, scope, card, to)
        return card and to and table.contains(player:getTableMark("@[player]ym2__fengkuangpaidui-round"), to.id)
    end,
    bypass_distances = function(self, player, skill, card, to)
        return card and to and table.contains(player:getTableMark("@[player]ym2__fengkuangpaidui-round"), to.id)
    end,
})
fengkuangpaidui:addAcquireEffect(function (self, player, is_start)
    player.room:addSkill("#CenterArea")
end)
return fengkuangpaidui